﻿using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Service.FileStrategy
{
    /// <summary>
    /// 上下文，通过这个来调用具体的策略
    /// </summary>
    public class FileOperateContext
    {
        /// <summary>
        /// 文件操作抽象类
        /// </summary>
        private FileOperateStrategy _fileOperateStrategy;
        
        /// <summary>
        /// 上传文件列表
        /// </summary>
        private List<IFormFile> _formFiles;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="fileOperateStrategy">参数为抽象类父类支持其对应的所有子类传入</param>
        /// <param name="formFiles">上传文件的列表</param>
        public FileOperateContext(FileOperateStrategy fileOperateStrategy, List<IFormFile> formFiles)
        {
            _fileOperateStrategy = fileOperateStrategy;
            _formFiles = formFiles;
        }

        /// <summary>
        /// 外部通过构造函数传入对应抽象类的子类，根据传入的子类调用其子类中对应实现的上传方法
        /// 若构造的是localStrategy，则对应调用的是LocalStrategy中的Upload方法
        /// 若构造的是QiNiuStrategy，则对应调用的是QiNiuStrategy中的Upload方法
        /// </summary>
        /// <returns></returns>
        public async Task<string> ContextInterface()
        {
            return await _fileOperateStrategy.Upload(_formFiles);
        }
    }
}
